use axum::Json;
use rfd::FileDialog;
use serde_json::{json, Value};

use crate::code;


pub async fn pick_folder() -> Result<Json<Value>, Json<Value>> {
    let files = FileDialog::new()
    .set_directory("/")
    .pick_folder();
    if let Some(f) = files {
        let s = f.to_str().unwrap_or_default();
        let s = s.replace("\\", "/");
        return code::data(json!(s))
    }
    code::data(json!(null))
}
pub async fn pick_file() -> Result<Json<Value>, Json<Value>> {
    let files = FileDialog::new()
    .set_directory("/")
    .pick_file();
    if let Some(f) = files {
        let s = f.to_str().unwrap_or_default();
        let s = s.replace("\\", "/");
        return code::data(json!(s))
    }
    code::data(json!(null))
}